package com.atguigu.gmall.weball.controller;

import com.atguigu.gamll.feign.product.ProductSkuDetailFeignClient;
import com.atguigu.gmall.product.vo.SkuDetailVo;
import com.atguigu.gamll.feign.item.SkuDetailFeignClient;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author lhh
 * @ClassName ItemController
 * @date 2022 2022/12/3
 */
@Controller
public class ItemController {

    @Resource
    SkuDetailFeignClient skuDetailFeignClient;

    @Resource
    ProductSkuDetailFeignClient productSkuDetailFeignClient;

    /**
     * 商品详情页
     * @param skuId
     * @return
     */
    @GetMapping("/{skuId}.html")
    public String item(@PathVariable Long skuId, Model model){

        SkuDetailVo skuDetailVo = skuDetailFeignClient.getSkuDetails(skuId).getData();

        //1、分类视图 {category1Id、category2Id、category3Id、category1Name、category2Name、category3Name}
        model.addAttribute("categoryView",skuDetailVo.getCategoryView());
        // sku信息 {基本信息、图片列表}包含skuImageList
        model.addAttribute("skuInfo",skuDetailVo.getSkuInfo());
        //实时价格
        BigDecimal bigDecimal = productSkuDetailFeignClient.getPrice(skuId).getData();
        model.addAttribute("price",bigDecimal);
        //4、所有销售属性集合
        model.addAttribute("spuSaleAttrList",skuDetailVo.getSpuSaleAttrList());
        //5、valuesSkuJson
        model.addAttribute("valuesSkuJson",skuDetailVo.getValuesSkuJson());
        return "item/index";
    }
}
